package com.margo.project.web.workbench.interceptor;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

import org.springframework.aop.support.StaticMethodMatcherPointcutAdvisor;
import org.springframework.core.annotation.AnnotationUtils;

import com.margo.project.web.workbench.done.WorkbenchDone;
import com.margo.project.web.workbench.todo.WorkbenchTodo;

public class WorkbenchAttributeSourceAdvisor extends StaticMethodMatcherPointcutAdvisor{
	
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	@SuppressWarnings("unchecked")
	private static final Class<? extends Annotation>[] AUTHZ_ANNOTATION_CLASSES =
            new Class[] {
            		WorkbenchTodo.class, WorkbenchDone.class,
            };

	
	
	@Override
	public boolean matches(Method method, Class<?> targetClass) {
		return isAuthzAnnotationPresent(method);
	}
	
    private boolean isAuthzAnnotationPresent(Method method) {
        for( Class<? extends Annotation> annClass : AUTHZ_ANNOTATION_CLASSES ) {
            Annotation a = AnnotationUtils.findAnnotation(method, annClass);
            if ( a != null ) {
                return true;
            }
        }
        return false;
    }

}
